#include "Solution.h"
#include <iostream>

using namespace std;

int main()
{
	int n;
	cin>>n;
	vector<int> num(n);
	for(int i=0;i<n;i++)
		cin>>num[i];

	vector<vector<int> > result = Solution().permute(num);

	for(size_t i=0;i<result.size();i++)
	{
		for(size_t j=0;j<result[i].size();j++)
			cout<<result[i][j]<<" ";
		cout<<endl;
	}

	while(cin.get() != '\n');
	cin.get();
}